﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data;
using CsvHelperPlus;


namespace csvread
{

    class Program
    {
        static void Main(string[] args)
        {
            UsingCsvHelperPlus();
            //UsingCsvHelperPlusToSave();
        }

        //static public void UsingCsvHelper()
        //{
        //    List<string> ticker = new List<string>();
        //    using (var fileReader = File.OpenText(@"P:\NetValue\production17\portfolio\desTrade\20170116.desTrade.csv"))
        //    using (var csvResult = new CsvHelper.CsvReader(fileReader))
        //    {
        //        while (csvResult.Read())
        //        {
        //            string stringField = csvResult.GetField<string>("#tk");
        //            ticker.Add(stringField);
        //        }
        //        Console.WriteLine("ok");
        //    }
        //}

        static public void UsingCsvHelperPlus()
        {
            string file = @"P:\univ\20180110.univ.csv";
            //DataTable dt = CsvHandler.ReadCSV(file);
            DataTable dt = CsvHandler.ReadCsvToDataTable(file, convert: new Dictionary<string, Type>() { {"PRICE",typeof(float)},{"HIGH", typeof(float)}});
            Console.WriteLine("read ok");
        }


        static public void UsingCsvHelperPlusToSave()
        {
            string path = @"D:\yy_temp\TestCsvHelpPlus.csv";
            Repo rp = new Repo();
            rp.id = 1;
            rp.price = 12.5f;
            rp.produceTime = new DateTime(1993, 12, 23);
            rp.name = "垃圾";
            List<Repo> listRepo = new List<Repo>();
            for(int i=0;i<10;i++){
                listRepo.Add(rp);
            }
            CsvHandler.ListSave2CSV(path, listRepo);
        }
    }

    public class Repo
    {
        public int id;
        public float price;
        public DateTime produceTime;
        public string name;
    }
}
